<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
</head>

<body>
    <div id="app"></div>
    <template id="my-app">
        <button @click="change">修改firstName</button>
        <h2>computed: {{fullName}}</h2>
        <h2>computed: {{fullName}}</h2>
        <h2>computed: {{fullName}}</h2>
        <h2>computed: {{fullName}}</h2>
        <hr>
        <h2>methods: {{getFullName()}}</h2>
        <h2>methods: {{getFullName()}}</h2>
        <h2>methods: {{getFullName()}}</h2>
        <h2>methods: {{getFullName()}}</h2>
    </template>
    <script>
        const App = {
            template: "#my-app",

            data() {
                return {
                    firstName: "三",
                    lastName: "张",
                    // fullName: "张三"
                }
            },
            methods: {
                getFullName() {
                    console.log('methods中getFullName')
                    return this.firstName + this.lastName
                },
                change() {
                    this.firstName = "四"
                }
            },
            computed: {
                fullName() {
                    //计算属性是有缓存的,当我们多次使用计算属性时计算属性中的逻辑只会执行一次
                    console.log('computed中fullName执行了')
                    return this.firstName + this.lastName
                }
            }
        }
        Vue.createApp(App).mount('#app')
    </script>
</body>

</html>